package cn.fay.chapter15;

import java.lang.reflect.Array;
import java.util.Arrays;

public class GenericArray<T> {
	private T[] array;
	public GenericArray(Class<T> type,int size) {
		array=(T[]) Array.newInstance(type, size);
	}
	public void put(int index,T item) {
		array[index]=item;
	}
	@SuppressWarnings({ "unused", "unchecked" })
	private T get(int index) {
		return array[index];
	}
	
	@SuppressWarnings("unchecked")
	public T[] rep() {
		return array;
	}
	public static void main(String[] args) {
		GenericArray<Integer> ga=new GenericArray<Integer>(Integer.class,10);
		for (int i = 0; i < 10; i++) {
			ga.put(i, i);
		}
		for (int i = 0; i < 10; i++) {
			System.out.print(ga.get(i)+" ");
		}
		System.out.println();
		System.out.println(Arrays.toString(ga.rep()));;
		
	}
}
